close all;
clearvars;
clc;

% Define MAT files
MATfile = {
    'sph01_scan185_raw.mat';     % bar 2 SPM/KCl/FeCl3 pH 3.0
    'sph02_scan224_raw.mat';     % bar 3
    'sph02_scan406_raw.mat';     % bar 3
    'sph02_scan442_raw.mat';     % bar 2 100 mM KCl + 5mM FeCl3 pH 2
};

% Select a file
FileSelect = 3;

% Load data from the selected file
data = load(MATfile{FileSelect});
mon = data.mon;
qz = data.qz;
ct = data.ct;
energy = data.energy;
mca = data.mca;

% Define energy range
rng = energy < 8.1 & energy > 1.9;
% rng=energy>6 & energy< 7.5;
% rng=energy>12;

% Smoothing
smear = ones(5,1);
mca_new = convn(mca, smear, 'same');
mca_conv = log (mca_new + 1) ;

%change qz
qz_new = qz/0.0218;

% Create contour plot
figure;
contourf(qz_new, energy(rng), mca_conv(rng,:), [0:1:8], 'LineColor', 'none');


colorbar;
% Additional plot settings
colorbarHandle = colorbar;
set(colorbarHandle, 'TickDirection', 'out');   % Set colorbar ticks to 'out'
set(colorbarHandle, 'LineWidth', 2);           % Set colorbar boundary and tick thickness
set(colorbarHandle, 'FontName', 'Arial');
set(colorbarHandle, 'FontSize', 25);% Set the colorbar font to Arial
% set(colorbarHandle, 'Ticks', [0 1 2 3 4]);

set(gca, 'FontName', 'Arial'); % Set the axes font to Arial
set(gca, 'ydir', 'normal');
set(gca, 'ytick', [2:1:14]);
set(gca, 'ylim', [2 7.5]);
set(gca, 'xlim', [0.46 1.6]);
% set(gca, 'xtick', [0.01:0.005:0.035]);
set(gca, 'fontsize', 25);
set(gca, 'LineWidth', 2);
set(gca, 'TickDir', 'out');
xlabel('${\alpha_i}/{\alpha_c}$', 'Interpreter', 'latex', FontSize = 35);
ylabel('Energy (keV)',FontSize=30);


axis square;
% grid on; % Uncomment if grid is needed